/**
 ***********************************************************************************************************
 * 
 ***********************************************************************************************************
 * @file RBDAEReader.h
 ***********************************************************************************************************/

#ifndef __RBDAEREADER_H__
#define __RBDAEREADER_H__

#ifdef  HEADER_ONCE
#pragma HEADER_ONCE
#endif

#ifdef  HEADER_MSG
#pragma HEADER_MSG(RBDAEReader.h)
#endif

/***********************************************************************************************************
 * Includes
 ***********************************************************************************************************/
#include "RBStreamReader.h"
#include "RBGeometry.h"
#include "RBMaterial.h"

/***********************************************************************************************************
 * Forward declarations
 ***********************************************************************************************************/

class RBGeometry;
class RBVertexBuffer;
class RBVertexDeclaration;
class RBIndexBuffer;
class RBRenderer;
class RBCamera;
class RBLight;
class RBSceneManager;

class FCDocument;
class FCDCamera;
class FCDGeometry;
class FCDGeometryMesh;
class FCDGeometryPolygons;
class FCDLight;
class FCDMaterial;
class FCDSceneNode;
class FCDGeometryInstance;

RBDeclareHandle(RBTransformComponent);
RBDeclareHandle(RBEntity);

/***********************************************************************************************************
 * Classes
 ***********************************************************************************************************/

class RBDAEReader : public RBStreamReader
{
public:
				        RBDAEReader             ();
    virtual            ~RBDAEReader             ();

    virtual RBStream*   Load                    (const RBString& strFilename);

private:

    void                ParseLibraries          (FCDocument* pDocument, RBRenderer* pRenderer);

    void                CreateObjectFromGeometry (const FCDGeometry* pMesh, RBRenderer* pRenderer);
    void                CreateMaterialFromMaterial(const FCDMaterial* pMaterial, RBRenderer* pRenderer);
    void                CreateObjectFromNode     (const FCDSceneNode* pNode, RBRenderer* pRenderer, RBEntityHandle entity, RBTransformComponentHandle xFormParent);
    
    void                AddGeometryInstance      (RBEntityHandle entityHandle, RBTransformComponentHandle xFormHandle, FCDGeometry* pFCDGeometry, FCDGeometryInstance* pFCDGeometryInstance);
    void                AddCamera                (RBEntityHandle entityHandle, RBTransformComponentHandle xFormHandle, FCDCamera* pFCDCamera);
    void                AddLight                 (RBEntityHandle entityHandle, RBTransformComponentHandle xFormHandle, FCDLight* pFCDLight);


private:
    struct RBGeometryMultiSub
    {
        RBGeometryMultiSub () {}
        std::map<const FCDGeometryPolygons*, RBGeometryHandle> m_mPolygons;
    };

    typedef stdext::hash_map<const FCDGeometry*, RBGeometryMultiSub> GeometryMap;
    typedef stdext::hash_map<const FCDMaterial*, RBMaterial*> MaterialMap;

    GeometryMap m_mGeometries;
    MaterialMap m_mMaterials;
};


/***********************************************************************************************************/

#endif // __RBDAEREADER_H__